home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.ada,comp.lang.c++
- Path: alexandria.organon.com!alexandria!jsa
- From: jsa@organon.com (Jon S Anthony)
- Subject: Re: on OO differnces between Ada95 and C++
- In-Reply-To: nabbasi@qualcomm.com's message of 20 Feb 1996 06:37:46 GMT
- Message-ID: <JSA.96Feb21134417@organon.com>
- Sender: news@organon.com (news)
- Organization: Organon Motives, Inc.
- References: <4gbq7q$g08@qualcomm.com>
- Date: Wed, 21 Feb 1996 18:44:17 GMT
-
- In article <4gbq7q$g08@qualcomm.com> nabbasi@qualcomm.com (Nasser Abbasi) writes:
-
- Use child packages. For example,
-
- > Learning_Ada95_OO_features...
- > ...
- > Now the C++ way:
- >
- >
- > --------------- account.h -------------------
- > class Account
- > {
- > public:
- > typedef int Money_Type;
- > Money_Type Balance;
- > int Account_Id;
- > };
- >
- > -------------- saving_account.h -----------------
- >
- > #include "saving_account.h"
- > class Saving_Account : public Account
- > {
- > public:
- > Money_Type Interest;
- > };
- >
- > --------------- main.cpp -----------------
- >
- > #include <iostream.h>
- > #include "saving_account.h" // Notice: no need to include to base class
- > // Account in account.h
- > main()
- > {
- > Saving_Account The_Saving_Account;
- > Saving_Account::Money_Type The_Balance; // notice, Money_Type accessed
- > // through Saving_Account and
- > // no need to include the
- > // base class account
- >
- > cout << "Balance?";
- > cin >> The_Balance;
- > The_Saving_Account.Balance = The_Balance;
- >
- > return 1;
- >
- > }
-
- Ada version (from your stuff...):
-
- > ------------------ account.ads ---------------------------
- > package Account is
- > type Money_Type is new integer range 1..100; -- just as an example
- > type Account_Type is tagged
- > record
- > Balance : Money_Type;
- > Account_Id : Integer;
- > end record;
- > end Account;
-
- ----------------- Account-Savings.ads ----------------
-
- Package Account.Saving_Account is
-
- -- Note: all the stuff in Account is visible here
-
- type Saving_Account_Type is new Account.Account_Type with
- record
- Interest : Account.Money_Type;
- end record;
-
- end Saving_Account;
-
- > --------------- main.adb ---------------------------
- >
- with Account.Saving_Account;
- --
- -- Note: visibility of Account comes along with Saving_Account here.
-
- with ada.text_io; use ada.text_io;
-
- procedure main is
-
- package Money_IO is new Ada.Text_IO.Integer_IO(Account.Money_Type);
- The_Saving_Account : Saving_Account.Saving_Account_Type;
- The_Balance : Account.Money_Type;
- begin
- Money_IO.Get(The_Balance);
- The_Saving_Account.Balance := The_Balance;
- end main;
- --
- Jon Anthony
- Organon Motives, Inc.
- 1 Williston Road, Suite 4
- Belmont, MA 02178
-
- 617.484.3383
- jsa@organon.com
-
-